﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using ETWebApi2.Models;
using IBLL;
using BllFactory;
using System.Web;

namespace ETWebApi2.Controllers
{
    [RoutePrefix("Cuser")]
    public class CuserController : ApiController
    {

        private ICUser_tbService userSv = ServiceFactory.CreatService<ICUser_tbService>();
        // GET api/cuser
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
        
        /// <summary>
        /// 登录验证 
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        /// -1 登录密码有误
        ///-2  该用户不合法(对应多个活动账号或者系统不存在该用户)
        ///0(普通员工) 或 1 （管理员）
        [Route("cuser")]
        [HttpGet]
        public int Get(string phone,string pwd)
        {
            int role = -5;
            List<CUser_tb> login = userSv.GetList(u => u.Phone == phone && u.State == 1);
            if (login.Count > 0 && login.Count == 1)
            {
                if (login[0].UserPwd == pwd)
                {
                    role =Convert.ToInt32(login[0].Role);
                }
                else
                {
                    role = -1;
                }
            }
            else
            {
                role = -2;
            }
            return role;
        }

        // POST api/cuser
        public void Post([FromBody]string value)
        {
        }

        // PUT api/cuser/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/cuser/5
        public void Delete(int id)
        {
        }
    }
}
